import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/constant/constant.dart';
import 'package:flutter_ncsjqz_getx/widget/app_bar_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/gradient_button.dart';
import 'package:flutter_ncsjqz_getx/widget/ink_widget.dart';
import 'package:get/get.dart';

import '../user_info_setting_logic.dart';
import 'set_sex_logic.dart';

/// <summary>
/// author：设置性别
/// dateTime： 2021/12/11 10:17
/// filePath： lib/page/my/userinfo_setting/set_sex/set_sex_view.dart
/// desc:
/// <summary>
///
class SetSexPage extends StatefulWidget {
  final int? index;
  SetSexPage(this.index);
  @override
  _SetSexPageState createState() => _SetSexPageState();
}

class _SetSexPageState extends State<SetSexPage> {
  final logic = Get.put(SetSexLogic());

  @override
  Widget build(BuildContext context) {
    logic.setIndex(widget.index);
    return GetBuilder<SetSexLogic>(
      builder: (controller) {
        return Scaffold(
          appBar: appBarWidget(title: "性别"),
          backgroundColor: Colors.white,
          body: Padding(
            child: Column(
              children: [
                InkWell(
                  child: Padding(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        InkWidget.title("男"),
                        Icon(Icons.check,color: logic.index == 1 ?Colors.green:Colors.transparent,),
                      ],
                    ),
                    padding: EdgeInsets.symmetric(vertical: 10),
                  ),
                  onTap: (){
                    logic.setIndex(1);
                  },
                ),
                InkWell(
                  child: Padding(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        InkWidget.title("女"),
                        Icon(Icons.check,color: logic.index == 2 ?Colors.green:Colors.transparent,),
                      ],
                    ),
                    padding: EdgeInsets.symmetric(vertical: 10),
                  ),
                  onTap: (){
                    logic.setIndex(2);
                  },
                ),
                Container(
                  width: Get.width * 0.7,
                  height: 40,
                  child: gradientButton("确定",circular: 40,onTap: (){
                    Map<String,dynamic> map = {"id":Constant.userDetailData!.id,"sex":logic.index};
                    Get.put(UserInfoSettingLogic()).setUserInfo(map);
                    Get.back( result: logic.index);
                  }),
                ),
              ],
            ),
            padding: EdgeInsets.symmetric(horizontal: 20),
          ),
        );
      },
    );
  }

  @override
  void dispose() {
    Get.delete<SetSexLogic>();
    super.dispose();
  }
}